#define  _CRT_SECURE_NO_WARNINGS 1
#include"List.h"
ListNode* BuyListNode(DataType x)
{
	ListNode* node = (ListNode*)malloc(sizeof(ListNode));
	if (!node)
	{
		perror("BuyListNode");
		exit(-1);
	}
	node->data = x;
	node->next = NULL;
	node->prev = NULL;
	return node;
}
ListNode* BuyListNode(DataType x)
{
	ListNode* node = (ListNode*)malloc(sizeof(ListNode));
	if (!node)
	{
		perror("BuyListNode");
		exit(-1);
	}
	node->data = x;
	node->next = NULL;
	node->prev = NULL;
	return  node;
}
ListNode* InitList()
{
	ListNode* head = BuyListNode(-1);
	head->next = head;
	head->prev = head;
	return head;
}
void ListPrint(ListNode* head)
{
	assert(head);
	ListNode* cur = head->next;
	while (cur)
	{
		printf("%d", cur->data);
		cur = cur->next;
	}
	printf("\n");
}
void ListPrint(ListNode* head)
{
	assert(head);
	ListNode* cur = head->next;
	while (cur)
	{
		printf("%d", cur->data);
		cur = cur->next;
	}
	printf("\n");
}
void ListPushBack(ListNode* head,DataType x)
{
	assert(head);
	ListNode* newnode = BuyListNode(x);
	ListNode* tail = head->prev;
	tail->next = newnode;
	newnode->prev = tail;
	newnode->next = head;
	head->next = newnode;
}

void ListPushBack(ListNode* head, DataType x)
{
	ListNode* newnode = BuyListNode(x);
	ListNode* tail = head->prev;
	tail->next = newnode;
	newnode->prev = tail;
	newnode->next = head;
	head->prev = newnode;
}
void ListPushFront(ListNode* head, DataType x)
{
	assert(head);
	ListNode* next = head->next;
	ListNode* newnode = BuyListNode(x);
	head->next = newnode;
	newnode->prev = head;
	newnode->next = next;
	next->prev = newnode;
}
void ListPopBack(ListNode* head)
{
	assert(head);
	ListNode* tail = head->prev;
	ListNode* tailPrev = tail->prev;
	free(tail);
	tailPrev->next = head;
	head->prev = tailPrev;
}
void ListPopFront(ListNode* head)
{
	assert(head);
	ListNode* next = head->next;
	next->next->prev = head;
	head->next = next->next;
	free(next);
}
void ListInsert(ListNode* pos,DataType x)
{
	ListNode* prev = pos->prev;
	ListNode* newnode = BuyListNode(x);
	newnode->next = pos;
	pos->prev = newnode;
	prev->next = newnode;
	newnode->prev = prev;
}